﻿/*
 * Authors:    Kęstutis Džiautas
 *             Edmundas Matusevičius
 * University: VU, MIF, SE, 4 course
 * Date:       2010-12-18
 * Version:    1.0
 */

using System.Collections.Generic;

namespace SemAnalyzer {
    class Tree {
        public Tree() {
            tree = new List<TreeNode>();
            root = new TreeNode();
        }

        /// <summary>
        /// Creates root node of the tree.
        /// </summary>
        /// <param name="content">Node content.</param>
        /// <param name="type">Node type</param>
        public void addRoot(string content, TreeNode.TreeNodeType type) {
            // initialize new node
            TreeNode rootNode = new TreeNode();
            rootNode.content = content;
            rootNode.type = type;

            // add node to tree
            tree.Add(rootNode);

            // mark as a root node
            root = rootNode;
        }

        /// <summary>
        /// Adds father for the node.
        /// </summary>
        /// <param name="content">Node content.</param>
        /// <param name="type">Node type.</param>
        /// <param name="child">Child node of the new father.</param>
        public void addFather(string content, TreeNode.TreeNodeType type, TreeNode child) {
            // initialize new node
            TreeNode fatherNode = new TreeNode();
            fatherNode.content = content;
            fatherNode.type = type;
            fatherNode.child = child;

            // add node to tree
            tree.Add(fatherNode);

            // mark as a root node
            root = fatherNode;
        }

        /// <summary>
        /// Adds child for the node.
        /// </summary>
        /// <param name="content">Node content.</param>
        /// <param name="type">Node type.</param>
        /// <param name="father">Father node of the new child.</param>
        public void addChild(string content, TreeNode.TreeNodeType type, TreeNode father) {
            // initialize new node
            TreeNode childNode = new TreeNode();
            childNode.content = content;
            childNode.type = type;
            childNode.father = father;

            // mark as child node
            father.child = childNode;

            // add node to tree
            tree.Add(childNode);
        }

        /// <summary>
        /// Adds brother for the node.
        /// </summary>
        /// <param name="content">Node content.</param>
        /// <param name="type">Node type.</param>
        /// <param name="brother">Brother node of the new brother.</param>
        public void addBrother(string content, TreeNode.TreeNodeType type, TreeNode brother) {
            // initialize new node
            TreeNode brotherNode = new TreeNode();
            brotherNode.content = content;
            brotherNode.type = type;
            
            // mark as brother node
            brother.brother = brotherNode;

            // add node to tree
            tree.Add(brotherNode);
        }

        public void addSubtree(Tree subtree, TreeNode brother) {
            
        }

        /// <summary>
        /// Tree root node.
        /// </summary>
        private TreeNode root;
        /// <summary>
        /// Tree.
        /// </summary>
        private List<TreeNode> tree;
    }
}
